import {
  OrderModel
} from '../../models/hdd/orderData.js'
let orderModel = new OrderModel()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    FId: '',
    price: '',
    starIndex1: 0,
    starIndex2: 0,
    starIndex3: 0,
    rateContent: '',
  },

  onChange1(e) {
    const index = e.detail.index;
    this.setData({
      'starIndex1': index
    })
  },

  onChange2(e) {
    const index = e.detail.index;
    this.setData({
      'starIndex2': index
    })
  },

  onChange3(e) {
    const index = e.detail.index;
    this.setData({
      'starIndex3': index
    })
  },

  rateContentInput(e) {
    this.setData({
      rateContent: e.detail.value
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    if(options.FId) {
      this.setData({
        FId: options.FId,
        price: options.price,
      })
    }
    wx.setNavigationBarTitle({
      title: '评价'
    })
    wx.setNavigationBarColor({
      frontColor: '#ffffff',
      backgroundColor: '#FF7136',
      animation: {
        duration: 400,
        timingFunc: 'easeIn'
      }
    })
  },

  submit() {
    orderModel.evaluateOrder({
      args: {
        orderId: this.data.FId,
        serviceStar: this.data.starIndex1,
        technologyStar: this.data.starIndex2,
        efficiencyStar: this.data.starIndex3,
        evaluate: this.data.rateContent,
        orderSum: this.data.price,
      }
    }).then(res => {
      if(res.data.success) {
        wx.showModal({
          showCancel: false,
          title: '提示',
          content: '评价成功',
          success(res) {
            if (res.confirm) {
              wx.navigateBack({
                delta: 2
              })
            }
          }
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})